package com.inphase.asset;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

/**
 * @author xiaob@inphase.com
 * @date 2017/9/21
 */
@Component
public class DbInit  implements CommandLineRunner {

    @Autowired
    DataSource dataSource;



    @Override
    public void run(String... args) throws Exception {
        String sql1 ="DROP TABLE IF EXISTS `student`";
        String sql2 ="CREATE TABLE `student` (" +
                "  `id` int(10) NOT NULL ," +
                "  `name` varchar(45) NOT NULL," +
                "  `psw` varchar(45) NOT NULL," +
                "        PRIMARY KEY (`id`)" +
                ")";

        dataSource.getConnection().createStatement().execute(sql1);
        dataSource.getConnection().createStatement().execute(sql2);
        dataSource.getConnection().createStatement().execute("INSERT INTO `student` VALUES ('2', '234', '234')");
        dataSource.getConnection().createStatement().execute("INSERT INTO `student` VALUES ('3', '234', '234')");
        dataSource.getConnection().createStatement().execute("INSERT INTO `student` VALUES ('16', '22', '22')");

    }
}
